<?php

//return string with images instead of text emots
function emots($string)
{
	global $conf;

	if(!$GLOBALS['emots_w']){
		$db = new dbquery;
		$db->cache('emots');
		$db->query("SELECT * FROM $conf[prefix]emots") or $db->err(__FILE__, __LINE__);

		$i=0;
		while($d=$db->fetch_object()){
			$exp=explode('||:||', $d->pattern);
			for($x=0;$x<count($exp);$x++){
				$GLOBALS['emots_w'][$i]=$exp[$x];
				$GLOBALS['emots_t'][$i]=string_template($d->output, array('theme_path'=>$GLOBALS['theme_path']));
				$i++;
			}
		}
	}

	for($i=0;$i<count($GLOBALS['emots_w']);$i++)
	$string=str_replace($GLOBALS['emots_w'][$i], $GLOBALS['emots_t'][$i], $string);

	return $string;
}
//

//funkcja zwracaj�ca b�d� wy�wietlaj�ca emoty parametr $how (print -> wypisuje, return zwraca)
function get_emots($kolumn, $how)
{
	global $conf, $lang, $thm_img;

	$db = new dbquery;
	$db->query("SELECT * FROM $conf[prefix]emots") or $db->err(__FILE__, __LINE__);
	$count=$db->num_rows();

	$emots='<TABLE CELLSPACING="0" CELLPADDING="0" BORDER="0">';

	for($i=0;$i<ceil($count/$kolumn);$i++)
	{
		$emots.="<TR>\n";
		for($x=0;$x<$kolumn;$x++)
		{
			if($d=$db->fetch_object())
			{
				$d->output=str_replace(' <', '<', $d->output);
				$output=string_template($d->output, array('theme_path'=>$GLOBALS['theme_path']));
				$emots.="<TD>&amp;nbsp;<A HREF=\"javascript:add_content('$d->input')\">$output</A>&amp;nbsp;</TD>\n";
			}
		}
		$emots.="</TR>\n";
	}

	$emots.='</TABLE>';

	if($how=='echo')
	echo($emots);
	elseif($how=='return')
	return $emots;
}
//

?>
